package mysql

import "gorm.io/gorm"

type User struct {
	gorm.Model
	Mobile   string `gorm:"type:varchar(30);not null;comment:'手机号'"`
	Password string `gorm:"type:varchar(30);not null;comment:'密码'"`
	ReMobile string `gorm:"type:varchar(30);not null;comment:'推荐人手机号'"`
	Age      int64  `gorm:"type:int(11);not null;comment:'年龄'"`
	Email    string `gorm:"type:varchar(500);not null;comment:'邮箱'"`
	Address  string `gorm:"type:varchar(100);not null;comment:'地址'"`
}

func (u *User) UserAdd(db *gorm.DB) error {
	return db.Debug().Create(u).Error
}

func (u *User) FindUserByMobile(db *gorm.DB, mobile string) error {
	return db.Debug().Where("mobile = ?", mobile).Find(u).Error
}

func (u *User) Login(db *gorm.DB) error {
	return db.Debug().Find(u).Error
}

func (u *User) UpdateUser(db *gorm.DB) error {
	return db.Debug().Updates(u).Error
}

func (u *User) FindUserById(db *gorm.DB, id int64) error {
	return db.Debug().Where("id = ?", id).First(u).Error
}
